﻿using System;
using log4net;
using Macds.Core.Log;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Macds.Test.Core.Log
{
    [TestClass]
    public class LogFactoryTest
    {
        [TestMethod]
        public void Logging_using_log4net_default_instance()
        {
            // Create default instance
            ILog logger = LogFactory.GetLog4netLogger();

            // To check the log entry using the default instance you must
            // open the log file RollingFile.log created in the folder Debug\App_Data\logs
            logger.Info("Log entry");
        }

        [TestMethod]
        public void Logging_using_log4net_default_instance_with_custom_name()
        {
            // Create default instance
            ILog logger = LogFactory.GetLog4netLogger("unit_test");

            // To check the log entry using the default instance you must
            // open the log file unit_test.log created in the folder Debug\App_Data\logs
            logger.Info("Log entry");
        }

        [TestMethod]
        public void Log_custom_class_using_log4net_default_instance()
        {
            // You can write the value fo the property of any custom class using the
            // ObjectDebugManager class. This class return a string value of the current state of the object
            var model = new Mapping.Mocks.CustomerModel() { Name = "John", LastName = "Smith" };

            // Create ObjectDebugManager instance
            var manager = new ObjectDebugManager();
            manager.Add(model);

            // Create default instance
            ILog logger = LogFactory.GetLog4netLogger();

            // To check the log entry using the default instance you must
            // open the log file RollingFile.log created in the folder Debug\App_Data\logs
            logger.Info(manager.GetInfo());

            /* Log saved in the RollingFile.log
               2012-12-23 17:05:20,792 [9] INFO  Macds.Core.Log.LogFactory - ### LogObjectManager ###
               CustomerModel
               - Name:John
               - LastName:Smith
            */
        }
    }
}
